package controller.Actions;

import java.io.Serializable;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.Account;
import model.User;
import org.apache.log4j.Logger;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import dao.PlanAccountDAO;

public class SearchAllPlanAccountAction extends Action implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	final static Logger logger = Logger.getLogger(SearchAllPlanAccountAction.class);

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		try {
			User user = (User) request.getSession().getAttribute("User");
			if (user == null) {
				return mapping.findForward("erroAlias");
			} else {
				
				PlanAccountDAO paDAO = new PlanAccountDAO();

				ArrayList<Account> listPlanAccount = (ArrayList<Account>) paDAO.findPlans();
				paDAO.closeDAO();
				request.getSession().setAttribute("ListPlans", listPlanAccount);

				return mapping.findForward("relContasAlias");
			}
		} catch (Exception e

		) {
			logger.error("FINDALLPLANACCOUNT ", e);

			return mapping.findForward("erroAlias");

		}

	}

}
